<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <title>模块管理</title>
</head>

<body>

<div id="wrapper">
    <div  class="gray-bg">
        <div class="row  m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i> <a>系统管理</a>
                    </li>
                    <li class="active">
                        <strong>模块管理</strong>
                    </li>
                </ol>
                <%--<span class="navbar-right  m-r m-t-8"><a href="${ctx}/admin/user/add" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i> 新 增</a></span>--%>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
           <div class="fh-breadcrumb">
            <div class="fh-column">
                <div class="full-height-scroll">
                    <ul class="list-group elements-list">
                        <li class="">
                            <div id="jstree2">
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

            <div class="full-height">
                <div class="full-height-scroll white-bg border-left">
                    <div class="tab-content">
                        <div class="wrapper wrapper-content animated fadeInRight">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="search-area">
                                        <form role="form" class="form-inline" id="queryform">
                                            <label for="title">
                                                <input type="input" placeholder="模块名称" name="title"
                                                       id="title"
                                                       class="form-control form-filter"></label>
                                        <%--    <label for="logAcount">
                                                <input type="input" placeholder="操作账号" name="logAcount"
                                                       id="logAcount"
                                                       class="form-control form-filter"></label>--%>
                                            <button class="btn btn-primary" type="button" onclick="submitFilter()"> 查询</button>
                                            <button class="btn btn-primary" datatable-clear type="button"> 清除</button>
                                        </form>
                                    </div>
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover " id="data-table" >
                                        </table>
                                    </div>
                                </div>
                            </div>
                     </div>
                </div>
            </div>
            </div>
        </div>

    </div>
</div>






<!-- Page-Level Scripts -->
<script>
    $(document).ready(function(){
        var setting ={
            "ajax": {
                "url":  "${ctx}/admin/sys/module/list",
                "type": "POST"
            },
            "columns": [
                { "title": "模块名称", "data": "title",  "width": "18%","orderable": true  },
                { "title": "地址", "data": "url", "width": "20%","orderable": false  },
                { "title": "操作时间", "data": "createdate", "width": "19%","orderable": false  },
                { "title": "排序", "data": "orderno", "width": "10%","orderable": true  },
                { "title": "说明", "data": "intro","name":"log_operate", "width": "16%","orderable": false  },
                {"title": "操作", "data": null, "width": "15%", "orderable": false}
            ],
            "columnDefs": [
                {
                    "targets": 5,
                    "render": function (data, type, row, meta) {
                        return "<a class='btn btn-xs default btn-editable' onclick='update("+data.id+",\""+data.title+"\")' href='javascipt:void(0)'><i class='fa fa-pencil-square-o'></i> 更新 </a>" +
                                "<a class='btn btn-xs default btn-editable' data-opt data-opt-url='${ctx}/admin/sys/module/del' data-opt-pams='{\"id\":" + data.id + "}' data-opt-fun='refresh()'  ><i class='fa fa-minus-square-o'></i> 删除 </a>";
                    }
                }
            ],
            "order": [
                [ 3, "desc" ]
            ]
        };
        /* Init DataTables */
         var oTable = $('#data-table').DataTable(ehconfig.get_datatable_config(setting))
         submitFilter=function(){

             $('#data-table').DataTable().draw();

        }

        $('#jstree2').jstree(
                {
                'plugins':["wholerow","contextmenu"],
                'core' : {
                    'data' :{
                        'url': '${ctx}/admin/sys/module/tree',  //异步加载jstree html格式的数据地址
                        'data': function (node) {
                            return { 'id': node.id };
                        }
                    }
                },
                "contextmenu":{
                        "items": {
                            "create": {"label":"新建主菜单","action":function(){
                                parent.layer.open({
                                    type: 2,
                                    title: '新建主菜单',
                                    shadeClose: true,
                                    shade: 0.8,
                                    area: ['770px', '500px'],
                                    content: '${ctx}/admin/sys/module/add'
                                });
                            }},
                            "rename": {"label":"新建子菜单","action":function(data){
                                var inst = jQuery.jstree.reference(data.reference),
                                node = inst.get_node(data.reference);
                                parent.layer.open({
                                    type: 2,
                                    title: '新建子菜单--'+node.text,
                                    shadeClose: true,
                                    shade: 0.8,
                                    area: ['770px', '450px'],
                                    content: '${ctx}/admin/sys/module/add?pid='+node.id
                                });
                            //    alert(node.id+"|"+node.text)
                            }},
                            "remove": {"label":"刷新","action":function(data){
                                $('#jstree2').jstree("refresh");
                            }},
                            "ccp": null,
                        }
                    }
                }).on("activate_node.jstree", function (e, data) {
            /*  console.log("The selected nodes are:");
              console.log(data.node.id);               //选择的node id
              console.log(data.node.text);            //选择的node text*/
            $('#data-table').DataTable().ajax.url("${ctx}/admin/sys/module/list?pid="+data.node.id+"&id="+data.node.id+"&or=true").load();
        });

    });
    var refresh =function(){
        $('#jstree2').jstree("refresh");
        $('#data-table').DataTable().draw();
    }

    var update =function(id,title){
        parent.layer.open({
            type: 2,
            title: '更新菜单-'+title,
            shadeClose: true,
            shade: 0.8,
            area: ['770px', '450px'],
            content: '${ctx}/admin/sys/module/update?id='+id
        });
    }
//    function clean() {
    //        $('#title').val('');
    //        $('#data-table').DataTable().draw();
    //    }
</script>

</body>

</html>
